package com.traffic.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.traffic.domain.PerLeaveRequests;
import com.traffic.service.IPerLeaveRequestsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 请假申请Controller
 * 
 * @author 郭世纪
 * @date 2024-12-08
 */
@RestController
@RequestMapping("/requests")
public class PerLeaveRequestsController extends BaseController
{
    @Autowired
    private IPerLeaveRequestsService perLeaveRequestsService;

    /**
     * 查询请假申请列表
     */
    @RequiresPermissions("attendance:requests:list")
    @GetMapping("/list")
    public TableDataInfo list(PerLeaveRequests perLeaveRequests)
    {
        startPage();
        List<PerLeaveRequests> list = perLeaveRequestsService.selectPerLeaveRequestsList(perLeaveRequests);
        return getDataTable(list);
    }

    /**
     * 导出请假申请列表
     */
    @RequiresPermissions("attendance:requests:export")
    @Log(title = "请假申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PerLeaveRequests perLeaveRequests)
    {
        List<PerLeaveRequests> list = perLeaveRequestsService.selectPerLeaveRequestsList(perLeaveRequests);
        ExcelUtil<PerLeaveRequests> util = new ExcelUtil<PerLeaveRequests>(PerLeaveRequests.class);
        util.exportExcel(response, list, "请假申请数据");
    }

    /**
     * 获取请假申请详细信息
     */
    @RequiresPermissions("attendance:requests:query")
    @GetMapping(value = "/{overtimeId}")
    public AjaxResult getInfo(@PathVariable("overtimeId") Long overtimeId)
    {
        return success(perLeaveRequestsService.selectPerLeaveRequestsByOvertimeId(overtimeId));
    }

    /**
     * 新增请假申请
     */
    @RequiresPermissions("attendance:requests:add")
    @Log(title = "请假申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PerLeaveRequests perLeaveRequests)
    {
        return toAjax(perLeaveRequestsService.insertPerLeaveRequests(perLeaveRequests));
    }

    /**
     * 修改请假申请
     */
    @RequiresPermissions("attendance:requests:edit")
    @Log(title = "请假申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PerLeaveRequests perLeaveRequests)
    {
        return toAjax(perLeaveRequestsService.updatePerLeaveRequests(perLeaveRequests));
    }

    /**
     * 删除请假申请
     */
    @RequiresPermissions("attendance:requests:remove")
    @Log(title = "请假申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{overtimeIds}")
    public AjaxResult remove(@PathVariable Long[] overtimeIds)
    {
        return toAjax(perLeaveRequestsService.deletePerLeaveRequestsByOvertimeIds(overtimeIds));
    }
}
